<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var arr = [10,22,14,4];

        // 取最大值
        console.log(Math.max(...arr));

        function max(){
            var num=arr[0];
            for(let i=0; i<arr.length;i++){
                num = num<arr[i]?arr[i]:num;
            }
            return num;
        }
        console.log(max());


        // 求和
        console.log(arr.reduce((a,b)=>a+b));

        function add(){
            var num=0;
            for(let i=0; i<arr.length;i++){
                num += arr[i];
            }
            return num;
        }
        console.log(add());


    </script>
</body>
</html>